package com.ce.pms.occupation.model;

// Generated 2008-12-24 13:41:51 by Hibernate Tools 3.2.0.b9

import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Where;

import com.ce.pms.system.occupation.model.AbsentDocumentItemConfigDO;
import com.ce.pms.system.occupation.model.SendDocumentItemConfigDO;
import com.sitechasia.webx.core.model.IDomainObject;

/**
 * 实体名称:入伙资料的收发 关联数据表:OM_DOCUMENT_RECEIVE_SEND
 *
 * @author yandawei
 * @CreateDate:2008-12-24
 */
@Entity
@Table(name = "OM_DOCUMENT_RECEIVE_SEND")
public class DocumentReceiveSendDO implements IDomainObject {

	/**
	 * 主键
	 */
	@Id
	@GeneratedValue
	@Column(name = "DOCUMENT_RECEIVE_SEND_ID", unique = true, nullable = false)
	private Long keyword;

	/**
	 * 身份验证DO
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "IDENTITY_VALIDATE_ID", nullable = false)
	private IdentityValidateDO identityValidate;

	/**
	 * 发放日期
	 */
	@Temporal(TemporalType.DATE)
	@Column(name = "SEND_DOCUMENG_DATE", length = 19)
	private Date sendDocumengDate;

	/**
	 * 描述说明
	 */
	@Column(name = "DESCRIPTION", length = 200)
	private String description;

	/**
	 * 发放资料
	 */
	@ManyToMany(cascade=CascadeType.ALL)
	@Where(clause = "DOCUMENT_TYPE='001'")
	@org.hibernate.annotations.CollectionOfElements
	@JoinTable(
			name="OM_DOC_SEND_RELATION",
			joinColumns=@JoinColumn(name="DOCUMENT_RECEIVE_SEND_ID"),
			inverseJoinColumns=@JoinColumn(name="SEND_DOCUMENT_ITEM_ID"))
	private Set<SendDocumentItemConfigDO> sendDocumentItemConfigs = new HashSet<SendDocumentItemConfigDO>();

	/**
	 * 缺失资料
	 */
	@ManyToMany(cascade=CascadeType.ALL)
	@Where(clause = "DOCUMENT_TYPE='002'")
	@org.hibernate.annotations.CollectionOfElements
	@JoinTable(
			name="OM_DOC_SEND_RELATION",
			joinColumns=@JoinColumn(name="DOCUMENT_RECEIVE_SEND_ID"),
			inverseJoinColumns=@JoinColumn(name="SEND_DOCUMENT_ITEM_ID"))
	private Set<AbsentDocumentItemConfigDO> absentDocumentItemConfigs = new HashSet<AbsentDocumentItemConfigDO>();


	/**
	 * 功能描述:  新增缺失资料<br>
	 * @param configDO
	 * Create author:yandawei <br>
	 * Create on:2008-12-29  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void  addAbsentDocumentItem(AbsentDocumentItemConfigDO configDO){
		getAbsentDocumentItemConfigs().add(configDO);
	}

	/**
	 * 功能描述:  移除缺失资料<br>
	 * @param configDO
	 * Create author:yandawei <br>
	 * Create on:2008-12-29  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void removeAbsentDocumentItem(AbsentDocumentItemConfigDO configDO){
		for (Iterator it = this.getAbsentDocumentItemConfigs().iterator(); it.hasNext();) {
			AbsentDocumentItemConfigDO  itemConfigDO = (AbsentDocumentItemConfigDO) it.next();
			if (itemConfigDO.getKeyword().equals(configDO.getKeyword())) {
				this.getAbsentDocumentItemConfigs().remove(itemConfigDO);
				break;
			}
		}
	}
	/**
	 * 功能描述:  新增发送资料<br>
	 * @param configDO
	 * Create author:yandawei <br>
	 * Create on:2008-12-29  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void  addSendDocumentItem(SendDocumentItemConfigDO configDO){
		getSendDocumentItemConfigs().add(configDO);
	}

	/**
	 * 功能描述:  移除发送资料<br>
	 * @param configDO
	 * Create author:yandawei <br>
	 * Create on:2008-12-29  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void removeSendDocumentItem(SendDocumentItemConfigDO configDO){
		for (Iterator it = this.getSendDocumentItemConfigs().iterator(); it.hasNext();) {
			SendDocumentItemConfigDO  itemConfigDO = (SendDocumentItemConfigDO) it.next();
			if (itemConfigDO.getKeyword().equals(configDO.getKeyword())) {
				this.getSendDocumentItemConfigs().remove(itemConfigDO);
				break;
			}
		}
	}


	public DocumentReceiveSendDO() {
	}

	public DocumentReceiveSendDO(Long keyword) {
		this.keyword = keyword;
	}

	public Set<AbsentDocumentItemConfigDO> getAbsentDocumentItemConfigs() {
		return absentDocumentItemConfigs;
	}

	public void setAbsentDocumentItemConfigs(
			Set<AbsentDocumentItemConfigDO> absentDocumentItemConfigs) {
		this.absentDocumentItemConfigs = absentDocumentItemConfigs;
	}

	public IdentityValidateDO getIdentityValidate() {
		return identityValidate;
	}

	public void setIdentityValidate(IdentityValidateDO identityValidate) {
		this.identityValidate = identityValidate;
	}

	public Long getKeyword() {
		return keyword;
	}

	public void setKeyword(long keyword) {
		this.keyword = keyword;
	}

	public Set<SendDocumentItemConfigDO> getSendDocumentItemConfigs() {
		return sendDocumentItemConfigs;
	}

	public void setSendDocumentItemConfigs(
			Set<SendDocumentItemConfigDO> sendDocumentItemConfigs) {
		this.sendDocumentItemConfigs = sendDocumentItemConfigs;
	}

	public Date getSendDocumengDate() {
		return this.sendDocumengDate;
	}

	public void setSendDocumengDate(Date sendDocumengDate) {
		this.sendDocumengDate = sendDocumengDate;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
